package com.cxc.controller;

import com.cxc.config.DynamicDataSource;
import com.cxc.entity.DbConfigration;
import com.cxc.service.TestService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈先冲
 * @date 2023/5/12
 */

@RestController
@RequiredArgsConstructor
public class TestController {
    private final TestService testService;
    private final RedissonClient redissonClient;

    @PostMapping(value = "/setDb")
    public void setDb() {
        DbConfigration zhangSanDb = new DbConfigration()
                .setHost("127.0.0.1")
                .setPort("3306")
                .setDbName("testdb")
                .setUsername("root")
                .setPassword("123456");
        redissonClient.getMap("sites").put("zhangsan",zhangSanDb);
    }

    @PostMapping(value = "/test")
    public Object test(@Param("name") String name) {
        DynamicDataSource.setLoginNameKey(name);
        return testService.test();
    }
}
